home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH19 / SHMAPP1.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-17  |  3.2 KB  |  130 lines

  1. ; SHMAPP1.ASM
  2. ;
  3. ; This is a shared memory application that uses the static shared memory
  4. ; TSR (SHARDMEM.ASM).  This program inputs a string from the user and
  5. ; passes that string to SHMAPP2.ASM through the shared memory area.
  6. ;
  7. ;
  8.         .xlist
  9.         include     stdlib.a
  10.         includelib    stdlib.lib
  11.         .list
  12.  
  13. dseg        segment    para public 'data'
  14. ShmID        byte    0
  15. dseg        ends
  16.  
  17. cseg        segment    para public 'code'
  18.         assume    cs:cseg, ds:dseg, es:SharedMemory
  19.  
  20. ; SeeIfPresent-    Checks to see if the shared memory TSR is present in memory.
  21. ;        Sets the zero flag if it is, clears the zero flag if
  22. ;        it is not.  This routine also returns the TSR ID in CL.
  23.  
  24. SeeIfPresent    proc    near
  25.         push    es
  26.         push    ds
  27.         push    di
  28.         mov    cx, 0ffh        ;Start with ID 0FFh.
  29. IDLoop:        mov    ah, cl
  30.         push    cx
  31.         mov    al, 0            ;Verify presence call.
  32.         int    2Fh
  33.         pop    cx
  34.         cmp    al, 0            ;Present in memory?
  35.         je    TryNext
  36.         strcmpl
  37.         byte    "Static Shared Memory TSR",0
  38.         je    Success
  39.  
  40. TryNext:    dec    cl            ;Test USER IDs of 80h..FFh
  41.         js    IDLoop
  42.         cmp    cx, 0            ;Clear zero flag.
  43. Success:    pop    di
  44.         pop    ds
  45.         pop    es
  46.         ret
  47. SeeIfPresent    endp
  48.  
  49.  
  50.  
  51. ; The main program for application #1 links with the shared memory
  52. ; TSR and then reads a string from the user (storing the string into
  53. ; shared memory) and then terminates.
  54.  
  55. Main        proc
  56.         assume    cs:cseg, ds:dseg, es:SharedMemory
  57.         mov    ax, dseg
  58.         mov    ds, ax
  59.         meminit
  60.  
  61.         print
  62.         byte    "Shared memory application #1",cr,lf,0
  63.  
  64. ; See if the shared memory TSR is around:
  65.  
  66.         call    SeeIfPresent
  67.         je    ItsThere
  68.         print
  69.         byte    "Shared Memory TSR (SHARDMEM) is not loaded.",cr,lf
  70.         byte    "This program cannot continue execution.",cr,lf,0
  71.         ExitPgm
  72.  
  73. ; If the shared memory TSR is present, get the address of the shared segment
  74. ; into the ES register:
  75.  
  76. ItsThere:    mov    ah, cl        ;ID of our TSR.
  77.         mov    al, 10h        ;Get shared segment address.
  78.         int    2Fh
  79.  
  80. ; Get the input line from the user:
  81.  
  82.         print
  83.         byte    "Enter a string: ",0
  84.  
  85.         lea    di, InputLine    ;ES already points at proper seg.
  86.         gets
  87.  
  88.         print
  89.         byte    "Entered '",0
  90.         puts
  91.         print
  92.         byte    "' into shared memory.",cr,lf,0
  93.  
  94.  
  95. Quit:        ExitPgm            ;DOS macro to quit program.
  96. Main        endp
  97.  
  98. cseg            ends
  99.  
  100. sseg        segment    para stack 'stack'
  101. stk        db    1024 dup ("stack   ")
  102. sseg        ends
  103.  
  104. zzzzzzseg    segment    para public 'zzzzzz'
  105. LastBytes    db    16 dup (?)
  106. zzzzzzseg    ends
  107.  
  108.  
  109. ; The shared memory segment must appear after "zzzzzzseg".
  110. ; Note that this isn't the physical storage for the data in the
  111. ; shared segment.  It's really just a place holder so we can declare
  112. ; variables and generate their offsets appropriately.  The UCR Standard
  113. ; Library will reuse the memory associated with this segment for the
  114. ; heap.  To access data in the shared segment, this application calls
  115. ; the shared memory TSR to obtain the true segment address of the
  116. ; shared memory segment.  It can then access variables in the shared
  117. ; memory segment (where ever it happens to be) off the ES register.
  118. ;
  119. ; Note that all the variable declarations go into an include file.
  120. ; All applications that refer to the shared memory segment include
  121. ; this file in the SharedMemory segment.  This ensures that all
  122. ; shared segments have the exact same variable layout.
  123.  
  124. SharedMemory    segment    para public 'Shared'
  125.  
  126.         include    shmvars.asm
  127.  
  128. SharedMemory    ends
  129.         end    Main
  130.